<?php
// 本类由系统自动生成，仅供测试用途
class GgoodsAction extends Action {
	public $hTitle = "喵星人星球--";
	public $type = 'ggoods';
	
	//主页面
    public function index(){
    	$this->assign('hTitle', $this->hTitle);
    	
    	$Goods = M('goods');
    	
    	//分页功能
		import("ORG.Util.Page");// 导入分页类
		$count      = $Goods->where("`type`='".$this->type."'")->count();// 查询满足要求的总记录数
		$Page       = new Page($count,12);// 实例化分页类 传入总记录数和每页显示的记录数
		//获取数据
		$data = $Goods->where("`type`='".$this->type."'")->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		

		$this->assign('data',$data);
    	
    	$this->display();
    }
    
    //AJAX调用瀑布流
    public function ajax(){
    	$Goods = M('goods');
    	$p = $this->_get('p');
    	
	    //分页功能
		import("ORG.Util.Page");// 导入分页类
		$count      = $Goods->where("`type`='".$this->type."'")->count();// 查询满足要求的总记录数
		$Page       = new Page($count,12);// 实例化分页类 传入总记录数和每页显示的记录数
		//获取数据
		$data = $Goods->where("`type`='".$this->type."'")->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		
		$this->assign('data',$data);
		
		if($Page->totalPages >= $p){
			$this->display();
		}
    }
    
    //详细信息页面
    public function info(){
    	$id = $this->_get('id');
    	
    	//获取商品信息
    	$Goods = M('goods');
    	$GoodInfo = $Goods->where("`id`='".$id."'")->find();
    	$this->assign('goodinfo',$GoodInfo);
    	
    	//获取商品图片信息
    	$Img = M('goods_img');
    	$ImgData = $Img->where("`gid`='".$id."'")->order('id desc')->limit('0,5')->select();
    	$this->assign('imgdata',$ImgData);
    	
    	$bbs = M('comments');
    	$bbsData = $bbs->where("`gid`='".$id."' and `cid` = '0' and `status` = '1'")->select();
    	$this->assign('bbsdata',$bbsData);
    	
    	//设置TITLE
    	$this->assign('hTitle', $GoodInfo['title'].'--'.$this->hTitle);
    	
	    $this->display();
    }
    
    //使用AJAX调用收藏功能
    public function coll(){
    	$id = $this->_get('id');
    	
	    $Goods = M('goods');
	    
	    var_dump($Goods->where('id ='.$id)->setInc('collection'));
	    
	    echo $Goods->getLastSql();
    }
    
    //addBBS 添加评论
    public function addBBs(){
    	$gid = $this->_get('gid');
    	$cid = $this->_get('cid','htmlspecialchars,strip_tags',0);
    	
    	$content = $this->_post('content');
	   	$bbs = M('comments');
	   	$data = array(
	   		'gid' => $gid,
	   		'content' => $content,
	   		'ctime' => time(),
	   	);
	   	
	   	if($cid != 0){
		   	$data['cid'] = $cid;
	   	}

	    if($bbs->where('id = '.$id)->add($data)){
		    echo "成功";
	    }else{
		    echo "失败";
	    }
    }
    
    //getcbbs
    public function getcbbs(){
    	$cid = $this->_get('cid');
    	
	   	$bbs = M('comments');
    	$bbsData = $bbs->where("`cid` = '{$cid}' and `status` = '1'")->select();
    	$this->assign('bbsdata',$bbsData);
    	
    	$this->display();
    }
}